package main

import (
	graph "code.google.com/p/feedgraph/graph/httpd"
	"code.google.com/p/feedgraph/config"
	"net/http"
	_ "net/http/pprof"
	"flag"
	"log"
)

const defaultAddr = ":8081"


func main() {

	master := flag.String("master", "", "IP:port of graphd instance with config info")
	addr := flag.String("addr", defaultAddr, "IP:port of this instance")

	flag.Parse()

	if *master != "" {

		ip, err := config.LocalIP()

		if err != nil {
			panic(err)
		}

		slave := ip.String() + *addr

		config.RegisterSlave(*master, slave)
		log.Println("waiting on masterd...")
		config.WaitForMaster(*master)
		log.Println("masterd seems ready")
		config.LoadFromMaster(*master)
	}

	for _, g := range config.Local.GraphConfig.Graphs {
	
		graph.AddGraph(g.ID, g.Capacity)
	}

	http.ListenAndServe(*addr, nil)
}
